home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / st / part01 / input.c next >
C/C++ Source or Header  |  1990-06-04  |  2KB  |  90 lines

  1. /* input.c
  2.    created by John Schultz, 10-Sep-89
  3.    
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/io.h>  
  8. #include <exec/ports.h>
  9. #include <exec/interrupts.h>  
  10. #include <proto/exec.h>
  11. #include <proto/graphics.h>
  12. #include <devices/input.h>
  13. #include <devices/inputevent.h>
  14. #include "input.h"
  15.  
  16. unsigned short volatile raw; /* raw key value */
  17.  
  18. struct MsgPort indevport;
  19. struct MsgPort * indevportptr;
  20. struct IOStdReq * inreqblockptr;
  21. struct Interrupt inhandler;
  22. struct InputEvent * eventp;
  23.  
  24. extern void totalinput();
  25.  
  26. int createti(void) {
  27.  
  28.   indevportptr = CreatePort("indevport",0);
  29.   if (!indevportptr) {
  30.     return 0;
  31.   }
  32.  
  33.   inreqblockptr = CreateStdIO((struct MsgPort *)indevportptr);
  34.   if (!inreqblockptr) {
  35.    DeletePort(indevportptr); 
  36.    return 0;
  37.   }
  38.  
  39.   inhandler.is_Data = (APTR)&raw;
  40.   inhandler.is_Code = totalinput;
  41.   inhandler.is_Node.ln_Pri = 51; /* One ahead of Intuition */
  42.  
  43.   if (OpenDevice("input.device",0L,
  44.                  (struct IORequest *)inreqblockptr,0L)) {
  45.     DeletePort(indevportptr);
  46.     DeleteStdIO(inreqblockptr);
  47.     return 0; 
  48.   }
  49.  
  50.   inreqblockptr->io_Command = IND_ADDHANDLER;
  51.   inreqblockptr->io_Data    = (APTR)&inhandler;
  52.   
  53.   if (DoIO((struct IORequest *)inreqblockptr)) {
  54.     DeletePort(indevportptr);
  55.     DeleteStdIO(inreqblockptr);
  56.     CloseDevice((struct IORequest *)inreqblockptr);
  57.     return 0;
  58.   }
  59.  
  60.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  61.   if(!GfxBase) {
  62.     DeletePort(indevportptr);
  63.     DeleteStdIO(inreqblockptr);
  64.     CloseDevice((struct IORequest *)inreqblockptr);
  65.     return 0;
  66.   }
  67.   FreeSprite(0);
  68.  
  69.   CloseLibrary((struct Library *)GfxBase);
  70.  
  71.   return 1;  
  72.  
  73. } /* end createti */
  74.  
  75. void deleteti(void) {
  76.  
  77.   if ((indevportptr) && (inreqblockptr)) {
  78.     inreqblockptr->io_Command = IND_REMHANDLER;
  79.     inreqblockptr->io_Data = (APTR)&inhandler;
  80.     DoIO((struct IORequest *)inreqblockptr);
  81.     CloseDevice((struct IORequest *)inreqblockptr);
  82.     DeleteStdIO(inreqblockptr);
  83.     DeletePort(indevportptr);
  84.   } /* end if */
  85.  
  86. } /* END deleteti */
  87.  
  88.  
  89. /* END input.c */
  90.